<?php

namespace app\admin\model;

use frame\lib\Db;

class Fake
{
    public static function list($query = '')
    {
        $uid = $_SESSION['admin']['id'];
        if ($query) {
            $list = Db::name('fake')->where(['delete_time' => 0 ,'adder_user_id' => 0])->like('fake', "%$query%")->select();
        } else {
            $list = Db::name('fake')->where(['delete_time' => 0,'adder_user_id' => 0])->select();
        }
        return $list;
    }
    public static function add($param)
    {
        $vip_time = self::vipTimeCompute(@$param['vip_type'], @$param['vip_count']);
        $data = [
            'vip_time' => @$vip_time,
            'status' => 0,
            'type' =>  $param['type'],
            'score' =>  @$param['score'] ?? 0,
            'adder_user_id' => 0
        ];
        for ($i = 0; $i < $param['num']; $i++) {
            $data['fake'] = randStr(10);
            $data['create_time'] = getTime();
            Db::name('fake')->insert($data);
        }
    }
    public static function vipTimeCompute($type , $count)
    {
        $day = 3600 * 24;
        switch ($type) {
            case 1:
                $vip_time = $day;
                break;
            case 2:
                $vip_time = $day * 30;
                break;
            case 3:
                $vip_time = $day * 365;
                break;
        }
        return $vip_time * $count;
    }
}
